package cn.itsource.ymcc.openfeign.fallbackfactory;

import cn.itsource.ymcc.openfeign.KillOpenFeign;
import cn.itsource.ymcc.result.JsonResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class KillOpenFeignFallbackFactory implements FallbackFactory<KillOpenFeign> {
    @Override
    public KillOpenFeign create(Throwable throwable) {
        return new KillOpenFeign() {
            @Override
            public JsonResult oneByOrder(Long id) {
                throwable.printStackTrace();//打印错误日志  打印到控制台
                log.error(throwable.getMessage());//记录日志
                return JsonResult.error("服务超时");//如果出现错误就返回给调用方
            }
        };
    }
}
